/**
 * 
 */
package com.core.util;

import java.io.Serializable; 
import java.util.List;
import org.hibernate.criterion.DetachedCriteria;

/**
 * @author laker
 * 
 */
public class GenericServiceHibernate<T, PK extends Serializable> implements GenericService<T, PK> {

	private GenericDAO<T, Serializable> dao;

	/**
	 * @return the dao
	 */
	public GenericDAO<T, Serializable> getDao() {
		return dao;
	}

	/**
	 * @param dao
	 *            the dao to set
	 */
	public void setDao(GenericDAO<T, Serializable> dao) {
		this.dao = dao;
	}

	@Override
	public String save(T entry) throws Exception{
		dao.save(entry);
		return null;
	}

	@Override
	public Pagination<T> find(T entry , int firstResult, int maxResults) {
		List<T> list = dao.findAll(entry , firstResult, maxResults);
		Long total = 0L;// dao.getTotalCount(entry);
		Pagination<T> p = new Pagination<T>(list, total.longValue(),maxResults);
		return p;
	}

	@Override
	public Pagination<T> search(final DetachedCriteria dc,final int firstResult,final int maxResults) {
		return dao.search(dc, firstResult, maxResults);
	}

	@Override
	public String delete(T entry) {
		boolean succ = this.dao.delete(entry);
		return String.valueOf(succ);
	}

	@Override
	public int getSize(String condition) {
		return 0;
	}

	@Override
	public String update(T entry) {
		boolean succ = this.dao.update(entry);
		return String.valueOf(succ);
	}

	@Override
	public List<T> getCondition(T entry) {
		return this.dao.getCondition(entry);
	}

	@Override
	public T findById(PK id) {
		return this.dao.findById(id);
	}

	@Override
	public List<T> likeBy(DetachedCriteria dc) {
		return this.dao.likeBy(dc);
	}

	protected void saveOrUpdate(T entry) throws Exception {
		
	}
}